import Vue from 'vue'
import LoadingTemplate from './index.vue'

const Loading = Vue.extend(LoadingTemplate)

let instance

export default{
    count:0,
    open () {
        this.count++
        if(!instance) {
            instance = new Loading({
                el:document.createElement('div')
            })
        }
        if(instance.loading) return
        document.body.appendChild(instance.$el)
        Vue.nextTick(() => {
            instance.loading = true
        })
    },
    close () {
        this.count--
            if(instance && this.count === 0 && instance != undefined) {
                instance.loading = false
            }else if(this.count < 0 && instance != undefined){
                this.count = 0
                instance.loading = false
        }
    }
}